package com.irdstudio.cdp.pboc.service.impl;

import java.util.List;
import java.util.Objects;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.irdstudio.cdp.pboc.service.dao.PbocBadDebtsDao;
import com.irdstudio.cdp.pboc.service.domain.PbocBadDebts;
import com.irdstudio.cdp.pboc.service.facade.PbocBadDebtsService;
import com.irdstudio.cdp.pboc.service.vo.PbocBadDebtsVO;
import com.irdstudio.basic.framework.core.base.FrameworkService;
/**
 * <p>ServiceImpl: 呆账信息汇总				<p>
 * @author ligm
 * @date 2018-12-26
 */
@Service("pbocBadDebtsService")
public class PbocBadDebtsServiceImpl implements PbocBadDebtsService, FrameworkService {
	
	private static Logger logger = LoggerFactory.getLogger(PbocBadDebtsServiceImpl.class);

	@Autowired
	private PbocBadDebtsDao pbocBadDebtsDao;
	
	/**
	 * 新增操作
	 */
	public int insertPbocBadDebts(PbocBadDebtsVO inPbocBadDebtsVo)  throws Exception {
		logger.debug("当前新增数据为:"+ inPbocBadDebtsVo.toString());
		int num = 0;
		try {
			PbocBadDebts pbocBadDebts = new PbocBadDebts();
			beanCopy(inPbocBadDebtsVo, pbocBadDebts);
			num = pbocBadDebtsDao.insertPbocBadDebts(pbocBadDebts);
		} catch (Exception e) {
			logger.error("新增数据发生异常!", e);
			num = -1;
			throw e;
		}
		logger.debug("当前新增数据条数为:"+ num);
		return num;
	}

	/**
	 * 删除操作
	 */
	public int deleteByPk(PbocBadDebtsVO inPbocBadDebtsVo)  throws Exception {
		logger.debug("当前删除数据条件为:"+ inPbocBadDebtsVo);
		int num = 0;
		try {
			PbocBadDebts pbocBadDebts = new PbocBadDebts();
			beanCopy(inPbocBadDebtsVo, pbocBadDebts);
			num = pbocBadDebtsDao.deleteByPk(pbocBadDebts);
		} catch (Exception e) {
			logger.error("删除数据发生异常!", e);
			num = -1;
			throw e;
		}
		logger.debug("根据条件:"+ inPbocBadDebtsVo +"删除的数据条数为"+ num);
		return num;
	}


	/**
	 * 更新操作
	 */
	public int updateByPk(PbocBadDebtsVO inPbocBadDebtsVo)  throws Exception {
		logger.debug("当前修改数据为:"+ inPbocBadDebtsVo.toString());
		int num = 0;
		try {
			PbocBadDebts pbocBadDebts = new PbocBadDebts();
			beanCopy(inPbocBadDebtsVo, pbocBadDebts);
			num = pbocBadDebtsDao.updateByPk(pbocBadDebts);
		} catch (Exception e) {
			logger.error("修改数据发生异常!", e);
			num = -1;
			throw e;
		}
		logger.debug("根据条件:"+ inPbocBadDebtsVo +"修改的数据条数为"+ num);
		return num;
	}
	
	/**
	 * @description:根据报告编号进行查询（与一份报告一对一）
	 * @param pbocBadDebtsVo
	 * @return
	 * @date:2018年12月27日 下午7:49:03
	 * @author:hengyh
	 */
	@Override
	public PbocBadDebtsVO selectByReportId(PbocBadDebtsVO pbocBadDebtsVo)  throws Exception {
		logger.debug("当前查询参数信息为:"+ pbocBadDebtsVo);
		try {
			PbocBadDebts queryPbocBadDebts = new PbocBadDebts();
			beanCopy(pbocBadDebtsVo, queryPbocBadDebts);
			queryPbocBadDebts = pbocBadDebtsDao.selectByReportId(queryPbocBadDebts);
			if (Objects.nonNull(queryPbocBadDebts)) {
				PbocBadDebtsVO outPbocBadDebtsVo = beanCopy(queryPbocBadDebts, new PbocBadDebtsVO());
				logger.debug("当前查询结果为:"+ outPbocBadDebtsVo.toString());
				return outPbocBadDebtsVo;
			} else {
				logger.debug("当前查询结果为空!");
			}
		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);
			throw e;
		}
		return null;
	}
	
	/**
	 * 查询操作
	 */
	public PbocBadDebtsVO queryByPk(PbocBadDebtsVO inPbocBadDebtsVo) {
		
		logger.debug("当前查询参数信息为:"+ inPbocBadDebtsVo);
		try {
			PbocBadDebts queryPbocBadDebts = new PbocBadDebts();
			beanCopy(inPbocBadDebtsVo, queryPbocBadDebts);
			PbocBadDebts queryRslPbocBadDebts = pbocBadDebtsDao.queryByPk(queryPbocBadDebts);
			if (Objects.nonNull(queryRslPbocBadDebts)) {
				PbocBadDebtsVO outPbocBadDebtsVo = beanCopy(queryRslPbocBadDebts, new PbocBadDebtsVO());
				logger.debug("当前查询结果为:"+ outPbocBadDebtsVo.toString());
				return outPbocBadDebtsVo;
			} else {
				logger.debug("当前查询结果为空!");
			}
		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);
			throw e;
		}
		return null;
	}


	/**
	 * 查询用户权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<PbocBadDebtsVO> queryAllOwner(PbocBadDebtsVO pbocBadDebtsVo)  throws Exception {

		logger.debug("当前查询本人所属数据信息的参数信息为:");
		List<PbocBadDebtsVO> list = null;
		try {
			List<PbocBadDebts> pbocBadDebtss = pbocBadDebtsDao.queryAllOwnerByPage(pbocBadDebtsVo);
			logger.debug("当前查询本人所属数据信息的结果集数量为:"+ pbocBadDebtss.size());
			pageSet(pbocBadDebtss, pbocBadDebtsVo);
			list = (List<PbocBadDebtsVO>) beansCopy(pbocBadDebtss, PbocBadDebtsVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
			throw e;
		}
		
		return list;
	
	}


	/**
	 * 查询当前机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<PbocBadDebtsVO> queryAllCurrOrg(PbocBadDebtsVO pbocBadDebtsVo)  throws Exception {

		logger.debug("当前查询本人所属机构数据信息的参数信息为:");
		List<PbocBadDebts> pbocBadDebtss = pbocBadDebtsDao.queryAllCurrOrgByPage(pbocBadDebtsVo);
		logger.debug("当前查询本人所属机构数据信息的结果集数量为:"+pbocBadDebtss.size());
		List<PbocBadDebtsVO> list = null;
		try {
			pageSet(pbocBadDebtss, pbocBadDebtsVo);
			list = (List<PbocBadDebtsVO>) beansCopy(pbocBadDebtss, PbocBadDebtsVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
			throw e;
		}
		
		return list;
	
	}


	/**
	 * 查询当前机构及下属机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<PbocBadDebtsVO> queryAllCurrDownOrg(PbocBadDebtsVO pbocBadDebtsVo)  throws Exception {

		logger.debug("当前查询本人所属机构及以下数据信息的参数信息为:");
		List<PbocBadDebts> pbocBadDebtss = pbocBadDebtsDao.queryAllCurrDownOrgByPage(pbocBadDebtsVo);
		logger.debug("当前查询本人所属机构及以下数据信息的结果集数量为:"+ pbocBadDebtss.size());
		List<PbocBadDebtsVO> list = null;
		try {
			pageSet(pbocBadDebtss, pbocBadDebtsVo);
			list = (List<PbocBadDebtsVO>) beansCopy(pbocBadDebtss, PbocBadDebtsVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
			throw e;
		}
		
		return list;
	
	}

}
